<template>
  <div class="login">
    <div class="login-title">
      <h2>请先登录</h2>
    </div>

    <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
      <el-form-item label="账号">
        <el-input v-model="formLabelAlign.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" >
        <el-input v-model="formLabelAlign.region" type='password'></el-input>
      </el-form-item>
       <el-form-item>
    <el-button type="primary" @click="submitForm()">登录</el-button>
    <el-button @click="resetForm('ruleForm')">注册</el-button>
  </el-form-item>
    </el-form>
   
  </div>
</template>

<script>
export default {
  data() {
    return {
      labelPosition: "right",
      formLabelAlign: {
        name: "",
        region: "",
        type: ""
      }
    };
  },
  component: {},
  methods: {
    submitForm(){
      let data = {
        username:this.formLabelAlign.name,
        password:this.formLabelAlign.region
      }
      this.$http.login(data).then(res=>{
        localStorage.setItem("token",res.token) 
        // console.log('111',res)
        // console.log(data) 
        this.$router.push('/home')
        
     })
    },
    resetForm(){
      let data = {
        username:this.formLabelAlign.name,
        password:this.formLabelAlign.region,
        password2:this.formLabelAlign.region,
      }
        this.$http.regist(data)
    }
  }
};
</script>

<style lang="scss">

.login .el-form {
  width: 500px;
}
.login .el-form {
  width: 500px;
  height: 300px;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
}
.login-title{
  text-align: center;
  margin-top: 250px;
}
</style>